Skip to content

fix(v2): propagate Retina backing scale factor to WKWebView#5212

Draft
leaanthony wants to merge 1 commit into
masterfrom
fix/5111-wkwebview-devicepixelratio
Draft

fix(v2): propagate Retina backing scale factor to WKWebView#5212
leaanthony wants to merge 1 commit into
masterfrom
fix/5111-wkwebview-devicepixelratio

Conversation

@leaanthony

Copy link
Copy Markdown
Member

Summary

Fixes #5111

WKWebView does not automatically propagate the display's backing scale factor to JavaScript's devicePixelRatio when content is loaded via the custom wails:// URL scheme. This causes devicePixelRatio to return 1 on Retina displays, resulting in blurry canvas rendering for any app using <canvas> — terminal emulators, chart libraries, drawing tools, games, and code editors.

Changes

  • Added _setOverrideDeviceScaleFactor: SPI call in WailsContext.m after WKWebView initialization
  • Added SPI category declaration in WailsWebView.h
  • Added test in v2/test/5111/

The SPI is stable since macOS 10.11 and is used by Electron, Playwright, and WebKit's own test infrastructure.

Test plan

  • Build a Wails v2 app on macOS with a Retina display
  • Check window.devicePixelRatio returns 2 (not 1)
  • Verify canvas rendering is sharp at native resolution
  • Test on non-Retina display that devicePixelRatio returns 1

WKWebView does not automatically propagate the display's backing scale
factor to JavaScript's devicePixelRatio when content is loaded via a
custom URL scheme (wails://). This causes devicePixelRatio to return 1
on Retina displays, resulting in blurry canvas rendering.

Fix by calling _setOverrideDeviceScaleFactor: on the WKWebView after
initialization with the screen's backingScaleFactor. This SPI is stable
since macOS 10.11 and is used by Electron, Playwright, and WebKit's
own test infrastructure.

Fixes #5111
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc23755b-b2f6-4e7a-b47d-a9ad60dff30b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/5111-wkwebview-devicepixelratio

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leaanthony

Copy link
Copy Markdown
Member Author

🤖 PR Triage Review

Accepted

Propagates Retina backing scale factor to WKWebView (v2 macOS). Fixes high-DPI rendering.

Platform: macOS (v2)

Next Steps: Dispatching for Mac testing.


Reviewed by Wails PR Reviewer Bot

@leaanthony leaanthony added this to the v2.13.0 milestone May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WKWebView reports devicePixelRatio=1 on macOS Retina displays (custom URL scheme)

1 participant